<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ include file="../taglibs.jsp" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<link rel="stylesheet" type="text/css" href="${path}/static/lib/bootstrap-3.3.7-dist/css/bootstrap.css"/>
<link rel="stylesheet" href="${path}/static/lib/layui/css/layui.css" media="all">
</head>
<body>
	<form class="layui-form layui-form-pane" id="ajax_form"  method="post" onsubmit="return false">
	  <div class="layui-form-item">
	    <label class="layui-form-label">名字</label>
	    <div class="layui-input-inline">
	      <input type="text" name="name" autocomplete="off" placeholder="请输入标题" class="layui-input">
	    </div>
	  </div>
	  <div class="layui-form-item">
	    <label class="layui-form-label">年龄</label>
	    <div class="layui-input-inline">
	      <input type="text" name="age" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input">
	    </div>
	  </div>
	  <div class="layui-form-item">
	      <label class="layui-form-label">性别</label>
	      <div class="layui-input-block">
	        <input type="text" name="gender" id="date1" autocomplete="off" class="layui-input">
	      </div>
	  </div>
	  <div class="layui-form-item">
	      <label class="layui-form-label">出生日期</label>
	      <div class="layui-input-block">
	        <input type="text" name="birthday" id="date1" autocomplete="off" class="layui-input">
	      </div>
	  </div>
	  
	  
	  <div class="layui-form-item">
	    <button class="layui-btn" onclick="submitForm()" value="添加">跳转式提交</button>
	  </div>
	</form>

	<script src="${path}/static/lib/jquery-1.11.3.js"></script>
	<script src="${path}/static/lib/mylayer.js"></script>
	<script src="${path}/static/lib/util.js"></script>
	<script src="${path}/static/lib/layui/layui.js"></script>
	<script>
		layui.use(['form', 'laydate', 'layer'], function(){
		  var form = layui.form;
		  var layer = layui.layer;
		  var laydate = layui.laydate;
		 
		  
		});
		
		function submitForm() {
			$.ajax({
				url : "${path}/student/insert.action",
				type : "post",
				dataType : "json",
				data : $("#ajax_form").serialize(),
				success : function(jsonObj) {
					console.log(jsonObj);
					if(jsonObj.code == util.SUCCESS) {
						mylayer.successMsg(jsonObj.msg);
						//当你在iframe页面关闭自身时
						var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
						setTimeout(function(){
							parent.layer.close(index); //再执行关闭 
							// 刷新父页面
							window.parent.location.reload();
						},1000);
					} else {
						mylayer.errorMsg(jsonObj.msg);
					}
					
				}
			});
		}
</script>
</body>
</html>